package project7.Storage;

    import java.util.*;
    import java.sql.*;
/**
 *
 * @author root
 */
public class LocalStorage {

    private static LocalStorage instance;
    private ArrayList<MenuItem> menuItems = null;

    private LocalStorage(){
        menuItems = new ArrayList<MenuItem>();
    }

    public static LocalStorage getInstance(){
        if(instance==null)
            instance = new LocalStorage();

        return instance;
    }

    /**
     * Returns the menuItem by MenuItem name;
     *
     */
    public MenuItem getMenuItem(String itemName){
        for( MenuItem M : menuItems)
            if( M.getName().equalsIgnoreCase(itemName))
                return M;
        return  null;
    }


    /**
     *  TO BE IMPLEMENTED AFTER DATABASE STRUCTURE FINALIZED
     *
     */
    public boolean loadMenuItems(ResultSet r){
        ResultSet rs = r;

        try{
            while(rs.next()){
                menuItems.add(new MenuItem(rs.getString("name"), rs.getFloat("price"), rs.getString("category")));
            }
            rs.close();
            return true;
        }
        catch (SQLException e){ return false;}
    }

    public boolean isEmpty(){
        return menuItems.isEmpty();
    }

    public ArrayList<MenuItem> getMenuItems(){
        return menuItems;
    }


}
